import { assetManager, AssetManager } from 'cc';

export interface LoadBundleResult {
    bundle: AssetManager.Bundle | null;
    error?: string;
}

export default class GYLoader {
    /**
     * 加载Bundle资源包
     * @param bundleName Bundle名称
     * @returns Promise<LoadBundleResult>
     */
    public static loadBundle(bundleName: string): Promise<LoadBundleResult> {
        return new Promise((resolve) => {
            assetManager.loadBundle(bundleName, (err, bundle) => {
                if (err) {
                    resolve({
                        bundle: null,
                        error: err.message || '加载Bundle失败 name: ' + bundleName + ' err: ' + err + ''
                    });
                    return;
                }
                resolve({
                    bundle: bundle
                });
            });
        });
    }
}